<?php
	session_start();
	include_once("connect.php");
	mysql_select_db("progin_171_13509047",$con);

	if(isset($_FILES["avatar"]["name"]))
		$newava = $_FILES["avatar"]["name"];
	if(isset($_POST["email"]))
		$newemail = $_POST["email"];
	if(isset($_POST["about"]))
		$newaboutme = $_POST["about"];
	
	//echo $newava." ".$newemail." ".$newaboutme;
	
	$change_name = explode(".",$_FILES['avatar']['name']);
	
// UPDATE table_name
// SET column1=value, column2=value2,...
// WHERE some_column=some_value
	
	$new_filename = $_SESSION["uname"].".".$change_name[1]; //ganti nama file sesuai dengan username
	$sql_update = "UPDATE user SET email='$newemail', avatar='$new_filename', about_me='$newaboutme' WHERE ID=$_SESSION[userid];";
	mysql_query($sql_update);
	move_uploaded_file($_FILES["avatar"]["tmp_name"],"avatar/".$new_filename);
	include_once("close_con.php");
	
//	$_SESSION["avatar"] = $new_filename;
	
	//$redirect = "Location: profile.php?id=".$_SESSION["userid"];
	$redirect = "Location: profile.php?id=".$_SESSION["userid"];
	header($redirect);
?>